<?php

namespace App\Http\Controllers\Web;

use App\Http\Controllers\Controller;
use App\Repositories\ReserveRepository;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
class ReserveController extends Controller
{
    protected $takeoutRepository;
    /**
     * TakeoutController constructor.
     * @param $AddressRepository
     */
    //初始化
    public function __construct(ReserveRepository $reserveRepository){
        $this->reserveRepository = $reserveRepository;
    }

    //预定检查时间判断空房空桌
    public function checkDeskRoom(Request $request){
        $rules = [
            'shop_id'=>'required|integer|exists:shops,id',
            'arrive_time'=>'required|date',
        ];
        $messages = [
            'shop_id.*'=>    '商铺不存在',
            'arrive_time.*'=>'时间不可用',
        ];
        $validator = Validator::make($request->all(), $rules,$messages);
        if ($validator->fails()){
            return show(2003,$validator->errors()->first());
        }
        return $this->reserveRepository->checkDeskRoom($request->shop_id,$request->arrive_time);
    }

    //预定下单
    public function addOrder(Request $request){
        return $this->reserveRepository->addOrder($request->cart);
    }

    //预定小程序下单
    public function addOrderProgram(Request $request){
        return $this->reserveRepository->addProgramOrder($request->cart);
    }

    //申请退款
    public function  applyForRefund(Request $request){
        return $this->reserveRepository->applyForRefund($request->id,$request->token);
    }
    //我已到店
    public function arrivaledShop(Request $request){
        return $this->reserveRepository->arrivaledShop($request->id,$request->token);
    }
    //确定已到店
    public function sureArrivaled(Request $request){
        return $this->reserveRepository->sureArrivaled($request->id,$request->token);
    }
    //加菜
    public function addDishes(Request $request){
        return $this->reserveRepository->addDishes($request->cart,$request->token);
    }
    //呼叫服务员
    public function callAttendant(Request $request){
        return $this->reserveRepository->callAttendant($request->id,$request->token);
    }
    //生成邀请函
    public function buildInvitation(Request $request){
        return $this->reserveRepository->buildInvitation($request);
    }
    //显示邀请函
    public function showInvitation(Request $request){
        return $this->reserveRepository->showInvitation($request);
    }
//    //修改订单价格
//    public function changePrice(Request $request){
//        return $this->reserveRepository->changePrice($request);
//    }
}
